<template>
  <div class="dashboard-container">
    <div class="dashboard-text">
      <div class="card-panel" style="cursor:unset">
        <div class="card-panel-icon-wrapper icon-message">
          <i class="font_family icon-yingpan" />
        </div>
        <div class="card-panel-description">
          <div class="card-panel-text">
            磁盘容量
          </div>
          <div class="diskinfo"><p>已使用：{{ diskInfo.able }}</p><p>可用量：{{ diskInfo.usable }}</p><p>总容量：{{ diskInfo.total }}</p></div>
        </div>
      </div>
      <div class="card-panel" v-for="item in routesList" @click="gotoRouter(item)" :key="item.id">
        <div class="card-panel-icon-wrapper icon-people">
          <i :class="item.meta.icon" />
        </div>
        <div class="card-panel-description">
          <div class="card-panel-text">
            {{ item.meta.title }}
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import axios from 'axios'

export default {
  name: 'HomeIndex',
  computed: {
    routes() {
      return this.$router.options.routes
    }
  },
  data() {
    return {
      routesList: [],
      diskInfo: {}
    }
  },
  created() {
    this.routesList = []
    this.sortRoutes(this.routes)
    this.getDiskInfo()
  },
  methods: {
    // 排序路由表
    sortRoutes(routes) {
      if (routes === undefined) return
      routes.forEach((item) => {
        if (!item.hidden && item.children !== undefined && item.children.length === 0) {
          this.routesList.push(item)
        } else {
          this.sortRoutes(item.children)
        }
      })
    },
    // 跳转路由
    gotoRouter(router) {
      this.$router.push(router.path)
    },
    // 获取磁盘容量
    async getDiskInfo() {
      const data = await axios.get('http://180.142.131.36:18069/getDiskInfo')
      if (data.status !== 200) return this.$message.error('磁盘信息获取失败')
      this.diskInfo = data.data
    }
  }
}
</script>

<style lang="scss" scoped>
.dashboard {
  &-container {
    margin: 30px;
  }

  &-text {
    font-size: 30px;
    line-height: 46px;
  }
}

.dashboard-text {
  display: flex;
  flex-wrap: wrap;

  .card-panel {
    width: 20%;
    height: 108px;
    cursor: pointer;
    font-size: 12px;
    position: relative;
    overflow: hidden;
    color: #666;
    background: #fff;
    box-shadow: 4px 4px 40px rgba(0, 0, 0, 0.05);
    border-color: rgba(0, 0, 0, 0.05);
    margin: 20px;

    &:hover {
      .card-panel-icon-wrapper {
        color: #fff;
      }

      .icon-people {
        background: #40c9c6;
      }

      .icon-message {
        background: #36a3f7;
      }

      .icon-money {
        background: #f4516c;
      }

      .icon-shopping {
        background: #34bfa3;
      }
    }

    .icon-people {
      color: #40c9c6;
    }

    .icon-message {
      color: #36a3f7;
    }

    .icon-money {
      color: #f4516c;
    }

    .icon-shopping {
      color: #34bfa3;
    }

    .card-panel-icon-wrapper {
      height: 70px;
      width: 70px;
      float: left;
      margin: 14px 0 0 14px;
      padding: 16px;
      transition: all 0.38s ease-out;
      border-radius: 6px;
      display: flex;
      justify-content: center;
      align-items: center;

      i {
        font-size: 40px;
      }
    }

    .card-panel-icon {
      float: left;
      font-size: 48px;
    }

    .card-panel-description {
      float: right;
      font-weight: bold;
      margin: 26px;
      margin-left: 0px;

      .card-panel-text {
        text-align: right;
        line-height: 18px;
        color: rgba(0, 0, 0, 0.45);
        font-size: 16px;
        margin-bottom: 12px;
      }

      .card-panel-num {
        font-size: 20px;
      }
    }
  }
}

.diskinfo {
  font-weight: 400;
  font-size: 10px;
  width: 95px;
  word-break: break-word;
  line-height: 12px;
}
</style>
